<div id="wrapMain">
            <div class="wrap_1024" style="margin-bottom:40px">

            <div class='head_nav'><span class="icon-picture"></span> Update story Source</div>
            <div class="user_profile">
				
			
                                            <div class="row"> <!-- Start class row wrap upload image and submit button -->
                                            <div class="col-md-2">
                                            </div>
                                            <div class="col-md-10">
											<button type="submit" class="btn btn-primary mySubmit" id="submitUpdateStorySource">
							                    <i class="glyphicon glyphicon-hand-up"></i>
							                    <span>Đăng bài</span>
							                </button>
                                            </div> <!-- End of class col-md-10 wrap upload image and submit button -->
                                            </div><!-- End of class row wrap upload image and submit button -->
											
				</div> <!-- End of row -->
			</div><!-- end wrap_1024 -->
		</div><!-- end wrapMain -->
		
<!-- end #wrapMain -->		
		

<script type="text/javascript">
	$(document).ready(function(){
	
	    /*
	     * Submit event
	     */
	    $('button#submitUpdateStorySource').click(function(e){
		 
	    	e.preventDefault();
	    	$(".alert").remove();
	  		$('.userPostForm').css('opacity', '0.3');
			$('.formLoading')
			.css('width', $('#videoUpload').width())
			.css('height', $('#videoUpload').height())
			.css('opacity', '1')
			.css('z-index','9999').css('display', 'block');
			$('#wrapLoadMoreItems').css('display', 'block').center();

			$.ajax({
				// &manual=1 : Lấy những truyện chưa submit lần nào
				url: "<?php echo BASE_URL; ?>index.php?module=user&act=ajax&getUnknowStorySource=1",
				type : 'POST',
				cache : false,
				async: false,
				data :{submitScan: 1},
				success : function(allTruyen){
					
					
					if(allTruyen){
						allTruyen = $.parseJSON(allTruyen);
						/*
						Nếu có truyện trả về thì bắt đầu lặp truyện, get link từng truyện và nội dung tương ứng
						*/
						$.each(allTruyen, function(e, truyen){
						//console.log(truyen);
						
							/* truyen.url = truyen.get_linksource;
							truyen.story_id = truyen.id;*/
						
							updateStorySource(truyen);
						});
					}
				},
				complete: function(){
					$('.formLoading').hide();
		    		$('#wrapLoadMoreItems').hide();
		    		$('.userPostForm').css('opacity', '1');
				}
			});
			return;
	    });

	   	function updateStorySource(newData){
		   	storyType = newData.getlink_type;
	   		
	   		returnSend = false;
	   		
	   		$.ajax({
				url: "<?php echo HOME; ?>index.php?module=user&act=ajax&updateStorySource=1",
				type: 'POST',
				cache: false,
				//dataType: 'jsonp',
				async: false,
				timeout: 800000,
				data: {txtSource: storyType, txtLink: newData.getlink_source, storyId: newData.id},
				success: function(data1){
					
					
				},

				error: function(x, t, m) {
			        if(t==="timeout") {
			            alert("got timeout");
			        } else {
				        console.log(x);
				        console.log(t);
				        console.log(m);
			        	
			        }
			    },
				
				complete: function(jqXHR, textStatus){
					
				}
			});
	   	}

	   	function submitStoryChapterContent(storyId){
	   		$.ajax({
	    		url : "<?php echo BASE_URL; ?>index.php?module=user&act=ajax&submitStoryChapters=1",
	    		type : 'POST',
	    		cache: false,
	    		async: false,
	    		data: {story_id:storyId},
	    		success : function(data){	
		    		
	    			$('#wrapLoadMoreItems').css('display', 'none');
		    		if(data){
						returnData = $.parseJSON(data);
						if(returnData.error){
							
							//popupMessage('Lỗi', [returnData.error], 'alert-danger');
							if(returnData.fail_chapters){
								$.each(returnData.fail_chapters, function(i1, index1){
									console.log(index1);
									$('#report_chapter_content_table tbody').append('<tr><td>'+index1.truyen_id+'</td><td>'+index1.ten_truyen+'</td><td>'+index1.truyen_chuong_link_id+'</td><td>'+index1.thutu+'</td></tr>');
								});
							}
						}
		    		}
		    	}
	    	});
	   	}

	   	function updateStoryManualStatus(storyId){
	   		$.ajax({
	    		url : "<?php echo BASE_URL; ?>index.php?module=user&act=ajax&updateStoryManualStatus=1",
	    		type : 'POST',
	    		cache: false,
	    		data: {story_id:storyId},
	    		success: function(data){
					return;
		    	}
	   		});
	   	}
	    
	    $('.select2').select2({ width: '250' });
		$('#txtSource').select2({width: '150'});
	});
</script>

<script src="public/exts/js/jquery.center.js"></script>
